<template>
  <div class="ServiceCreate">
    <el-form :inline="true" :rules="rules" ref="form" :model="form" label-position="left" label-width="80px">
      <div style="position:absolute;left:420px;top:470px;">
        <el-button type="success" class="el-icon-star-off">帮助</el-button>
        <el-button type="primary" class="el-icon-thumb" @click="submitForm('form')">保存</el-button>
      </div>
      <div style="padding-left:100px;padding-top:70px">
        <div>
          <el-form-item label="服务类型" prop="serviceId">
            <el-select v-model="form.serviceId" placeholder="服务类型" @visible-change="getServeOptions()"
              style="width:400px">
              <el-option v-for="serve in serveOptions" :key="serve.id" :label="serve.name" :value="serve.id">
              </el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="概   要" prop="summary">
            <el-input v-model="form.summary" style="width:400px"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="客   户" prop="customerId">
            <el-select v-model="form.customerId" placeholder="选择" @visible-change="getCustomerOptions()"
              style="width:400px">
              <el-option v-for="customer in customerOptions" :key="customer.id" :label="customer.name"
                :value="customer.id"></el-option>
            </el-select>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="状   态">
            <el-input placeholder="新创建" :disabled="true" style="width:400px"></el-input>
          </el-form-item>
        </div>
        <el-form-item label="服务请求" prop="content">
          <el-input type="textarea" v-model="form.content" style="width:400px"></el-input>
        </el-form-item>
      </div>
      <div>
        <img src="../assets/create.png" width="500px" style="position:relative;top:-300px;left:600px;" />
      </div>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "ServiceCreate",
    props: ["msg"],
    data() {
      return {
        form: {
          // id: "",
          // serviceId: "",
          // summary: "",
          // customerId: "",
          // state: 1,
          // content: "",
          // createUserId: ""
        },
        serveOptions: [],
        customerOptions: [],
        role: {},
        rules: {
          serviceId: [{
            required: true, message: '请选择服务类型', trigger: 'blur'
          }],
          summary: [{
            max: 20, message: '最多20个字符', trigger: 'blur'
          }],
          customerId: [{
            required: true, message: '请选择客户', trigger: 'blur'
          }],
          content: [
            { required: true, message: '请输入服务请求',trigger: 'blur' },
            { max: 20, message: '最多20个字符', trigger: 'blur' }
          ],
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.onSubmit();
          } else {
            this.$message({
              message: '您还有未完善的选项',
              type: 'warning'
            })
            return false;
          }
        });
      },
      onSubmit() {
        let _this = this;
        this.form.createUserId = localStorage.getItem("userId") || "";
        this.$http.post("/serveList/create", this.form).then(function (ret) {
          if (ret.data.code == 0) {
            _this.form = {};
            _this.$notify({
              title: ret.data.msg,
              message: "😀",
              type: "success"
            });
          } else {
            _this.$notify.error({
              title: ret.data.msg,
              message: "😭",
              type: 'error'
            });
          }
        });
      },
      getCustomerOptions() {
        let _this = this;
        if (_this.customerOptions.length == 0) {
          _this.$http.get("/serveList/customerInfo").then(function (ret) {
            if (ret.data.code == 0) {
              _this.customerOptions = ret.data.data;
            } else {
              _this.customerOptions.push = ["暂无数据"];
            }
          });
        }
      },
      getServeOptions() {
        let _this = this;
        if (_this.serveOptions.length == 0) {
          _this.$http.get("/serveList/getServeType").then(function (ret) {
            if (ret.data.code == 0) {
              _this.serveOptions = ret.data.data;
            } else {
              _this.serveOptions.push = ["暂无数据"];
            }
          });
        }
      }
    }
  };
</script>

<style scoped>
</style>